/**
 * 方法说明
 * @method 方法名
 * @for 所属类名
 * @param {参数类型} 参数名 参数说明
 * @return {null} 返回值说明
 * @property 2021-07-27
 * @author 胡晓洋
 * @version 0.0.1
 */


export default class DrawPlane {
    constructor() {
        this.DataSource = null;
        this.EntityCollectionList = [];
    }
    delDataSource() {
        this.DataSource && viewer.dataSources.remove(this.DataSource);
    }

    init(positions) {
        viewer.scene.globe.depthTestAgainstTerrain = false;
        // viewer.dataSources.removeAll();
        this.DataSource = null;
        // // 清楚所有光柱  未写

        positions.forEach(position => {
            this.drawSinglePlane(position)
        })

    }
    drawSinglePlane(position) {
        this.DataSource = new Cesium.CustomDataSource('planeEntities' + position.eventid);
        this.EntityCollectionList.push(position.eventid)
        this.DataSource.entities.add({
            id: 'plane' + position.eventid,
            name: "plane",
            polygon: {
                hierarchy: new Cesium.PolygonHierarchy(
                    Cesium.Cartesian3.fromDegreesArray(position.coordinates)
                ),
                material: Cesium.Color.TURQUOISE.withAlpha(0.5), //  Cesium.Color.ORANGE.withAlpha(0.5),
                classificationType: Cesium.ClassificationType.BOTH,
                clampToGround: true,
                outline: true,
                outlineColor: new Cesium.Color(0.0, 0.0, 0.0, 1.0),
                outlineWidth: 2.0,
                arcType: Cesium.ArcType.RHUMB,
            },
        })
        var polyCenter = Cesium.BoundingSphere.fromPoints(Cesium.Cartesian3.fromDegreesArray(position.coordinates));
        var center = Cesium.Cartographic.fromCartesian(polyCenter.center);
        const longitude = (center.longitude / Math.PI) * 180;
        const latitude = (center.latitude / Math.PI) * 180;

        this.DataSource.entities.add({
            position: Cesium.Cartesian3.fromDegrees(longitude, latitude, 0),
            label: {
                text: position.num,
                color: Cesium.Color.fromCssColorString('#fff'),
                font: 'normal 14px MicroSoft YaHei',
                showBackground: true,
                outlineColor: new Cesium.Color(0.0, 0.0, 0.0, 1.0),
                outlineWidth: 2.0,
                heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
                scale: 1,
                pixelOffset: new Cesium.Cartesian2(0.0, 0.0),
                pixelOffsetScaleByDistance: new Cesium.NearFarScalar(1.5e2, 0.0, 8.0e6, 1.0),//根据距照相机的距离指定广告牌的像素偏移
                distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0.0, 50000.0),
            },
        })
        // this.DataSource.entities.add({
        //     id: 'planeOutLIne' + position.eventid,
        //     polyline: {
        //         positions: Cesium.Cartesian3.fromDegreesArray(position.coordinates),
        //         width: 1,
        //         material: Cesium.Color.ORANGE.withAlpha(0.8),
        //         depthFailMaterial: Cesium.Color.BLUE, //位于地下的材质,不给地下的材质，位于地下的线就不可见
        //         clampToGround: false, //折线固定在地面
        //         arcType: Cesium.ArcType.GEODESIC, //定义连接点采用的路径
        //     },

        // })

        viewer.dataSources.add(this.DataSource);
        viewer.flyTo(this.DataSource);
    }
    SourceshowHide(t) {
        this.EntityCollectionList.forEach(coll => {
            const poOBjArrsource = viewer.dataSources.getByName('planeEntities' + coll) || [];
            poOBjArrsource.forEach(item => {
                item.show = t;
            })
        })
    }
    changeProfileStyle(id) {
        let entBox = null;
        const poOBjArrsource = viewer.dataSources.getByName("planeEntities" + id) || [];
        if (poOBjArrsource.length) {
            entBox = poOBjArrsource[0].entities.getById(
                "plane" + id
            );
            // 设置线的颜色
            entBox.polygon.material = Cesium.Color.RED.withAlpha(0.5);
        }
        return entBox
    }
    backOriginalStyle(id) {
        const poOBjArrsource = viewer.dataSources.getByName("planeEntities" + id) || [];
        if (poOBjArrsource.length) {
            const entBox = poOBjArrsource[0].entities.getById(
                "plane" + id
            );
            // 设置线的颜色
            entBox.polygon.material = Cesium.Color.TURQUOISE.withAlpha(0.5); //  Cesium.Color.ORANGE.withAlpha(0.5);
        }
    }
}

